package com.gnerv.battle.boot.module.base.controller;

import com.gnerv.battle.boot.common.base.model.RestResult;
import com.gnerv.battle.boot.module.base.business.RoleBusiness;
import com.gnerv.battle.boot.module.base.model.dto.RoleAccountDTO;
import com.gnerv.battle.boot.module.base.model.dto.RoleCreateDTO;
import com.gnerv.battle.boot.module.base.model.dto.RoleDTO;
import com.gnerv.battle.boot.module.base.model.dto.RolePermissionDTO;
import com.gnerv.battle.boot.module.base.model.dto.RoleUpdateDTO;
import com.gnerv.battle.boot.module.base.model.dto.RoleViewDTO;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author Gnerv LiGen
 */
@RestController
@AllArgsConstructor
@RequestMapping(value = "api/manage/role")
public class RoleController {

    private final RoleBusiness roleBusiness;

    @PostMapping(value = "")
    public RestResult<Void> create(@RequestBody RoleCreateDTO roleCreateDTO) {
        return roleBusiness.create(roleCreateDTO);
    }

    @DeleteMapping(value = "")
    public RestResult<Void> deleteByUkId(@RequestParam(value = "ukId") String ukId) {
        return roleBusiness.deleteByUkId(ukId);
    }

    @PutMapping(value = "")
    public RestResult<Void> updateByUkId(@RequestBody RoleUpdateDTO roleUpdateDTO) {
        return roleBusiness.updateByUkId(roleUpdateDTO);
    }

    @PutMapping(value = "account/bind")
    public RestResult<Void> bindAccount(@RequestBody RoleAccountDTO roleAccountDTO) {
        return roleBusiness.bindAccount(roleAccountDTO);
    }

    @PutMapping(value = "permission/bind")
    public RestResult<Void> bindPermission(@RequestBody RolePermissionDTO rolePermissionDTO) {
        return roleBusiness.bindPermission(rolePermissionDTO);
    }

    @PutMapping(value = "view/bind")
    public RestResult<Void> bindView(@RequestBody RoleViewDTO roleViewDTO) {
        return roleBusiness.bindView(roleViewDTO);
    }

    @GetMapping(value = "")
    public RestResult<RoleDTO> selectByUkId(@RequestParam(value = "ukId") String ukId) {
        return roleBusiness.selectByUkId(ukId);
    }

    @GetMapping(value = "list")
    public RestResult<List<RoleDTO>> listByName(@RequestParam(required = false, value = "name") String name) {
        return roleBusiness.listByName(name);
    }

}
